if( !window.XMLHttpRequest ) XMLHttpRequest = function()
{
    try{ return new ActiveXObject("MSXML3.XMLHTTP") }catch(e){}
    try{ return new ActiveXObject("MSXML2.XMLHTTP.3.0") }catch(e){}
    try{ return new ActiveXObject("Msxml2.XMLHTTP") }catch(e){}
    try{ return new ActiveXObject("Microsoft.XMLHTTP") }catch(e){}
    throw new Error("Could not find an XMLHttpRequest alternative.")
};


function simpleAjax(url, data, onSucc, onError){
    var req = XMLHttpRequest();
    req.open("POST", url, true);
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
    req.onreadystatechange = function()
    {
        if (request.readyState == 4)
            if (request.status == 200) {
                if (onSucc) {
                    onSucc(req.responseText);
                }
            }
            else {
                if (onError) {
                    onError(req.responseText);
                }
            }
        }
    };
    req.send(data);
    return req
}


function jsonAjax(url, params, onSucc, onError)
{
    return simpleAjax(url, JSON.stringify(params),
        function (text) {
            if (onSucc) {
                onSucc(JSON.parse(text));
            }
        },
        function (text) {
            if (onError) {
                onError(text);
            }
        }
    );
}


function dynAjax(url, params)
{
    return simpleAjax(url, JSON.stringify(params), eval, null);
}


















